#!/usr/bin/perl -w # For syntax highlighting
package clreqd_modules;

use strict;
use vm_info;

sub vm_poweroff {
my %ARGS=@_;

	local $SIG{CHLD}='DEFAULT';
	my $type=$ARGS{TYPE};
	my $name=$ARGS{NAME};
	my $vm_info=new vm_info($type);
	if(!defined($vm_info)) {
		return "FAIL " . vm_info::error();
	}
	my $cmd=$vm_info->get_field("poweroff");
	if(!defined($cmd)) {
		return "FAIL " . vm_info::error();
	}
	if(substr($cmd,0,1) ne "/") {
		$cmd="$::ENV{TRUECL_CODE}/$cmd";
	}
	$cmd =~ s/\$\$APPNAME/$name/g;

	# The power-off is meant to be immediate, so wait

	::msg("Running '$cmd ...");
	my $txt=`$cmd </dev/null 2>&1`;
	if(!defined($txt)) {
		$txt="Failed to run command '$cmd' at all!";
		return "FAIL $txt";
	}
	my $rc=$?>>8;
	if($rc==0) {
		return "OK";
	} else {
		chomp $txt;
		return "FAIL $txt";
	}
}

1;
